(function (aopc) {
    aopc.addExpandPage(804, function (get) {
        const Common = get('UtilsCommon', 'Common');

        return {
            expandInit() {
                const startTime = this.getProperty('StartTime');
                startTime.dataSource = [this.getHours(), this.getMinutes()];
                const endTime = this.getProperty('EndTime');
                endTime.dataSource = [this.getHours(), this.getMinutes()];
                if (!this.pageData.MeetingId) this.pageData.MeetingId = Common.createGuid();

                //const on_off_view2 = this.getProperty('on_off_view2');
                //this.setOnOffProperty(on_off_view2);
            },
            setInit() {
                const on_off_view1 = this.getProperty('on_off_view1');
                this.setOnOffProperty(on_off_view1);
            },
            expandDataLoad({ data }) {
                this.isUpdate = data && data.MeetingId && !data.IsNew;
            },
            setOnOffProperty(on_off_view) {
                const theme = this.theme;
                on_off_view.properties.forEach(p => {
                    p.isEdit = true;
                    if (p.name === 'IsAsr') {
                        p.isVisible = this.visitUser.IsAsr === 1;
                    }
                    p.setValue = function (v) {
                        this.value = v;
                        const p2 = this.properties[0];
                        if (theme === 'red') p2.style.backgroundColor = v ? '#F92A2A' : '#EECACA';
                        else p2.style.backgroundColor = v ? '#2A9DF4' : '#BAC8DC';
                        p2.style.justifyContent = v ? 'flex-end' : 'flex-start';
                        p2.refresh && p2.refresh();
                    };
                    p.getValue = function () { return this.value ? 1 : 0; };
                });
            },
            getHours() {
                const dataSource = [];
                for (let i = 8; i < 24; i++) {
                    const v = (i < 10 ? '0' : '') + i;
                    dataSource.push({ Value: v, Text: v });
                }
                for (let i = 0; i < 8; i++) {
                    const v = (i < 10 ? '0' : '') + i;
                    dataSource.push({ Value: v, Text: v });
                }
                return dataSource;
            },
            getMinutes() {
                const dataSource = [];
                const list = ['00', '30', '10', '15', '20', '40', '45', '50', '25', '35', '55'];
                list.forEach(v => {
                    dataSource.push({ Value: v, Text: v });
                });
                for (let i = 0; i < 60; i++) {
                    const v = (i < 10 ? '0' : '') + i;
                    if (!list.includes(v)) dataSource.push({ Value: v, Text: v });
                }
                return dataSource;
            },
            setChecked({ property }) {
                property.setValue(!property.value);
            },
            expandSetEntityData({ entityData }) {
                if (parseInt(entityData.StartTime.replace(':', ''), 10) >= parseInt(entityData.EndTime.replace(':', ''), 10)) {
                    this.alert('会议结束时间必大于开始时间！');
                    return false;
                }
                entityData.StartDate = entityData.MeetingDate + " " + entityData.StartTime + ":00";
                entityData.EndDate = entityData.MeetingDate + " " + entityData.EndTime + ":00";
                entityData.IsBook = 1;
                entityData.MeetingRoomId = this.visitUser.MeetingRoomId;
                if (window.loginUser && !this.isUpdate) entityData.AdminUserId = window.loginUser.UserId;
                return entityData;
            },
            successCallback() {
                this.alertSuccess('保存成功！', () => this.toPage('/meetingSubjectEdit.html?ref=2&IsBook=true&MeetingId=' + this.pageData.MeetingId + "&backUrl2=" + encodeURIComponent(this.pageData.backUrl || '')))
            }
        }
    });
})(window.aopc);